package com.lx.bbs.controller;

import com.lx.bbs.entity.BizException;
import com.lx.bbs.entity.Result;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Component
@RestControllerAdvice
public class ExHandler {

    @ExceptionHandler(BizException.class)
    public Result handleBizException(BizException e){
        return new Result(0, e.getMessage(), e.getData());
    }

    @ExceptionHandler(Exception.class)
    public Result handleException(BizException e){
        e.printStackTrace();
        // 通知管理员处理问题 邮件/短信
        return new Result(0, "业务繁忙", null);
    }
}
